<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>玉灵 QQ:7031633 Email:webrx@126.com</title>
    <script src="js/axios/axios.js"></script>
</head>

<body>
<script>
    //配置
    axios.defaults.baseURL = 'http://localhost/api/';
    axios.defaults.timeout = 10000

    //请求拦截器
    axios.interceptors.request.use(function (config) {
        let token = '13014577033'

        //System.out.println(req.getHeader("token"));
        config.headers.token = token

        console.log(config.method)
        //post
        if (config.data !== undefined) {
            config.data = config.data.concat('&token='+token)
        }

        //get
        if (config.params !== undefined) {
            config.params.token = token
        }

        // 在发送请求之前做些什么
        console.log(config.data)
        console.log(config.params)
        console.log(config)

        return config
    }, function (error) {
        // 对请求错误做些什么
        return Promise.reject(error);
    })

    //响应拦截器
    axios.interceptors.response.use(response => {
        console.log(response)
        console.log(response.status)
        if (response.status === 403) {

        }
        return response
    })

    axios({
        url: 't4',
        method: 'post',
        //data: JSON.stringify({user: 'wangwu',id:999,name:'李四四'}),
        data: `user=wangwu&id=999&name=李四四`,
        headers:{'Content-Type' : 'application/x-www-form-urlencoded'}
    }).then(res => console.log(res)).catch(e => console.log(e))

    //get
    /*
    axios({
        url: 't4',
        method: 'get',
        params: {id: 2, name: 'lisi'}
    }).then(res => console.log(res)).catch(e => console.log(e))*/
</script>
</body>
</html>
